/*
 * AddMember.java
 *
 * Created on __DATE__, __TIME__
 */

package com.insigma.yanwenlong.bookkeeping.gui;

import java.sql.SQLException;

import javax.swing.JOptionPane;

import com.insigma.yanwenlong.bookkeeping.pojo.Member;
import com.insigma.yanwenlong.bookkeeping.service.MemberService;
import com.insigma.yanwenlong.bookkeeping.service.MemberServiceImpl;

/**
 *
 * @author  __USER__
 */
public class AddMember extends javax.swing.JFrame {
	private MemberService memberService = new MemberServiceImpl();

	/** Creates new form AddMember */
	public AddMember() {
		this.setTitle("添加成员");
		initComponents();
		this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
		this.setLocationRelativeTo(null);
	}

	/** This method is called from within the constructor to
	 * initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is
	 * always regenerated by the Form Editor.
	 */
	//GEN-BEGIN:initComponents
	// <editor-fold defaultstate="collapsed" desc="Generated Code">
	private void initComponents() {

		jLabel1 = new javax.swing.JLabel();
		jtfMember = new javax.swing.JTextField();
		btnAddMember = new javax.swing.JButton();

		setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

		jLabel1.setText("\u6210\u5458\u540d\u79f0\uff1a");

		btnAddMember.setText("\u6dfb\u52a0");
		btnAddMember.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				btnAddMemberActionPerformed(evt);
			}
		});

		javax.swing.GroupLayout layout = new javax.swing.GroupLayout(
				getContentPane());
		getContentPane().setLayout(layout);
		layout
				.setHorizontalGroup(layout
						.createParallelGroup(
								javax.swing.GroupLayout.Alignment.LEADING)
						.addGroup(
								layout
										.createSequentialGroup()
										.addGroup(
												layout
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.LEADING)
														.addGroup(
																layout
																		.createSequentialGroup()
																		.addGap(
																				24,
																				24,
																				24)
																		.addComponent(
																				jLabel1)
																		.addGap(
																				30,
																				30,
																				30)
																		.addComponent(
																				jtfMember,
																				javax.swing.GroupLayout.PREFERRED_SIZE,
																				123,
																				javax.swing.GroupLayout.PREFERRED_SIZE))
														.addGroup(
																layout
																		.createSequentialGroup()
																		.addGap(
																				78,
																				78,
																				78)
																		.addComponent(
																				btnAddMember)))
										.addContainerGap(
												javax.swing.GroupLayout.DEFAULT_SIZE,
												Short.MAX_VALUE)));
		layout.setVerticalGroup(layout.createParallelGroup(
				javax.swing.GroupLayout.Alignment.LEADING).addGroup(
				layout.createSequentialGroup().addGap(42, 42, 42).addGroup(
						layout.createParallelGroup(
								javax.swing.GroupLayout.Alignment.BASELINE)
								.addComponent(jtfMember,
										javax.swing.GroupLayout.PREFERRED_SIZE,
										javax.swing.GroupLayout.DEFAULT_SIZE,
										javax.swing.GroupLayout.PREFERRED_SIZE)
								.addComponent(jLabel1)).addPreferredGap(
						javax.swing.LayoutStyle.ComponentPlacement.RELATED, 87,
						Short.MAX_VALUE).addComponent(btnAddMember).addGap(60,
						60, 60)));

		pack();
	}// </editor-fold>
	//GEN-END:initComponents
	
	//点击添加
	private void btnAddMemberActionPerformed(java.awt.event.ActionEvent evt) {
		String name = jtfMember.getText();
		
		Member member = new Member();
		member.setName(name);
		
		try {
			int rowAffected = memberService.addMember(member);
			if(rowAffected > 0) {
				JOptionPane.showMessageDialog(this, "添加成员成功");
			}else {
				JOptionPane.showMessageDialog(this, "添加成员失败");
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

	/**
	 * @param args the command line arguments
	 */
	public static void main(String args[]) {
		java.awt.EventQueue.invokeLater(new Runnable() {
			public void run() {
				new AddMember().setVisible(true);
			}
		});
	}

	//GEN-BEGIN:variables
	// Variables declaration - do not modify
	private javax.swing.JButton btnAddMember;
	private javax.swing.JLabel jLabel1;
	private javax.swing.JTextField jtfMember;
	// End of variables declaration//GEN-END:variables

}